home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8400 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: passing arguments to main()
  5. Date: 4 Mar 1996 08:04:22 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4he866$qf2@hpbblb.bbn.hp.com>
  8. References: <4h78t1$nqq@netnews.upenn.edu>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:4h78t1$nqq@netnews.upenn.edu
  15.  
  16. daniels@oasis.rad.upenn.edu (Jamie Daniels) wrote:
  17. >Hello,
  18. >
  19. >I have a question about c I am not very good with programming. I have this 
  20. >project that I want to take two strings one a name the other being an 80
  21. >character message(sentence). I want it to spit out a simplt print statement at
  22. >an Unix prompt. But I don't know how to pass arguments to main(). also I can't 
  23. >get the output to be entered in at the unix prompt. I want the output to be a 
  24. >command. for a simple example
  25. >
  26. > printf("ping 165.234.323.222");
  27. >
  28. >will not ping this address it only prints this statement before the prompt
  29. >
  30. This function shouldn't do anything other :-)
  31.  
  32. But now to your problems, use main as it is defined:
  33. int main(int argc, char** argv)
  34. where argc is the number of arguments, argv an array of pointers to the 
  35. arguments. argv[0] is the command name (most your program name).
  36.  
  37. To execute your command (e.g. ping) use system() or pipe the output of
  38. your program to a shell.
  39.  
  40. Good luck,
  41. Matthias
  42.  
  43.